'use strict';
/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  /**
   * 后台管理
   */
  router.post('/api/upload/file', controller.uploadcos.file);

  /**
   * 用户权限相关
   */
  router.get('/api/dept/list', controller.dept.allList);
  router.resources('dept', '/api/dept', controller.dept);
  router.post('/api/user/login', controller.user.login);
  router.get('/api/user/list', controller.user.allList);
  router.get('/api/user/simpleList', controller.user.simpleList);
  router.post('/api/user/updateUserRoles', controller.user.updateUserRoles);
  router.get('/api/user/getUserRoles', controller.user.getUserRoles);
  router.get('/api/user/getUserInfo', controller.user.getUserInfo);
  router.resources('user', '/api/user', controller.user);
  router.get('/api/role/list', controller.role.allList);
  router.resources('role', '/api/role', controller.role);
  router.get('/api/menu/list', controller.menu.allList);
  router.resources('menu', '/api/menu', controller.menu);
  router.get('/api/memberUser/list', controller.memberUser.allList);
  router.resources('memberUser', '/api/memberUser', controller.memberUser);
  /**
   * 业务代码
   */
  // 小程序金刚区菜单
  router.get('/wx/wxMenu/list', controller.wxMenu.allList);
  router.get('/api/wxMenu/list', controller.wxMenu.allList);
  router.resources('wxMenu', '/api/wxMenu', controller.wxMenu);
  // 轮播图
  router.get('/wx/wxBanner/list', controller.wxBanner.allList);
  router.get('/api/wxBanner/list', controller.wxBanner.allList);
  router.resources('wxBanner', '/api/wxBanner', controller.wxBanner);
  // 新闻
  router.get('/wx/wxNews/list', controller.wxNews.allList);
  router.get('/api/wxNews/list', controller.wxNews.allList);
  router.resources('wxNews', '/api/news', controller.wxNews);

  // 区域管理
  router.get('/wx/district/tree', controller.district.tree);
  router.get('/wx/district/list', controller.district.allList);
  router.get('/api/district/tree', controller.district.tree);
  router.get('/api/district/list', controller.district.allList);
  router.resources('district', '/api/district', controller.district);

  // 会员用户管理
  router.post('/wx/member/register', controller.memberUser.register);
  router.post('/wx/member/login', controller.memberUser.login);
  router.post('/wx/member/wechatLogin', controller.memberUser.wechatLogin);
  router.get('/wx/member/info', controller.memberUser.info);
  router.put('/wx/member/updateInfo', controller.memberUser.updateInfo);
  router.put('/wx/member/changePassword', controller.memberUser.changePassword);
  router.put('/wx/member/bindPhone', controller.memberUser.bindPhone);
  router.resources('memberUser', '/api/memberUser', controller.memberUser);

  // 地址管理
  router.get('/wx/address/user', controller.address.getUserAddresses);
  router.post('/wx/address/setDefault', controller.address.setDefault);
  router.get('/wx/address/getDefault', controller.address.getDefault);
  router.resources('address', '/wx/address', controller.address);
  router.get('/api/address/user', controller.address.getUserAddresses);
  router.post('/api/address/setDefault', controller.address.setDefault);
  router.resources('address', '/api/address', controller.address);

  /**
   * 写字楼管理
   */
  // 写字楼盘
  router.get('/wx/officeBuildingTemplate/list', controller.officeBuildingTemplate.allList);
  router.get('/api/officeBuildingTemplate/list', controller.officeBuildingTemplate.allList);
  router.resources('officeBuildingTemplate', '/api/officeBuildingTemplate', controller.officeBuildingTemplate);
  router.resources('officeBuildingTemplateWx', '/wx/officeBuildingTemplate', controller.officeBuildingTemplate);
  // 写字楼
  router.get('/api/officeBuilding/list', controller.officeBuilding.allList);
  router.get('/api/officeBuilding/simpleList', controller.officeBuilding.simpleList);
  router.resources('officeBuilding', '/api/officeBuilding', controller.officeBuilding);
  router.get('/wx/officeBuilding/list', controller.officeBuilding.allList);
  router.resources('officeBuilding', '/wx/officeBuilding', controller.officeBuilding);
  // 跟进记录
  router.get('/api/houseFollowup/list', controller.houseFollowup.allList);
  router.resources('houseFollowup', '/api/houseFollowup', controller.houseFollowup);
  router.get('/wx/houseFollowup/list', controller.houseFollowup.allList);
  router.resources('houseFollowup', '/wx/houseFollowup', controller.houseFollowup);

  /**
   * 办公用品商城
   */
  // 商品分类
  router.get('/api/category/tree', controller.category.tree);
  router.get('/api/category/list', controller.category.allList);
  router.resources('category', '/api/category', controller.category);
  router.get('/wx/category/tree', controller.category.tree);
  router.get('/wx/category/list', controller.category.allList);
  router.resources('category', '/wx/category', controller.category);

  // 商品管理
  router.get('/api/product/list', controller.product.allList);
  router.resources('product', '/api/product', controller.product);
  router.get('/wx/product/list', controller.product.allList);
  router.resources('product', '/wx/product', controller.product);

  // 订单管理
  router.get('/api/order/list', controller.order.allList);
  // 微信支付相关
  // router.post('/api/order/createWxPayment', controller.order.createWxPayment);
  // router.get('/api/order/queryWxPayment', controller.order.queryWxPayment);
  // router.post('/api/order/refundOrder', controller.order.refundOrder);
  // router.get('/api/order/queryRefund', controller.order.queryRefund);
  // router.get('/api/order/listRefunds', controller.order.listRefunds);
  // 微信支付回调
  // router.post('/wx/payment/callback', controller.order.wxPaymentCallback);
  // router.post('/wx/refund/callback', controller.order.refundCallback);
  // 创建支付订单
  router.get('/api/payment/wx/create', controller.wxPay.createPayment);
  router.resources('order', '/api/order', controller.order);

  // 购物车管理
  router.get('/api/cart/count', controller.cart.count);
  router.post('/api/cart/clear', controller.cart.clear);
  router.post('/api/cart/update-num', controller.cart.updateNum);
  router.post('/api/cart/update-selected', controller.cart.updateSelected);
  router.post('/api/cart/update-all-selected', controller.cart.updateAllSelected);
  router.post('/api/cart/deleteAll', controller.cart.deleteAll);
  router.get('/api/cart/list', controller.cart.allList);
  router.post('/api/cart/settle', controller.cart.settle);
  router.resources('cart', '/api/cart', controller.cart);
};
